#pragma once

#ifndef DELETE_ISOLATED_MESH_HANDLER_H_
#define DELETE_ISOLATED_MESH_HANDLER_H_

#include <osg/ShapeDrawable>
#include <osgGA/GUIEventHandler>
#include <osgViewer/Viewer>
#include <osgUtil/LineSegmentIntersector>

class SelectIsolatedMeshHandler : public osgGA::GUIEventHandler
{
public:
	SelectIsolatedMeshHandler();

	bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa);

	osg::Geode *GetGeode();
	const osg::BoundingBox *GetBoundingBox();
	const osg::Vec3Array *GetBoundingBoxRectVertices();

	void StartEditing();
	void StopEditing();

	// void Clear();
protected:
	void _selectIsolatedMesh(osgViewer::Viewer *viewer, const osgGA::GUIEventAdapter &ea);
	bool _trackTriangularMesh(const osgUtil::LineSegmentIntersector::Intersection &intersection);

	float _x, _y;
	bool  _isSelectionValid;
	bool  _isEditing;

	osg::BoundingBox                 _boundingBox;
	osg::ref_ptr<osg::Vec3Array>     _boundingBoxRectVertices;

	osg::ref_ptr<osg::Geode>         _geode;
	osg::ref_ptr<osg::ShapeDrawable> _shapeDrawable_box;
	osg::ref_ptr<osg::Box>           _shape_box;
	osg::Vec4                        _color_box;
};

#endif // !DELETE_ISOLATED_MESH_HANDLER_H_
